<template>
  <div
    class="site-wrapper"
    v-loading.fullscreen.lock="loading"
    element-loading-text="拼命加载中"
     style="height:100%"
  >
    <template v-if="!loading">
      <main-navbar style="margin-bottom: 33px" v-if="!$route.meta.isturn" />
      <div class="navb" style="height:100%">
        <div class="" :style="{ 'min-height': documentClientHeight + 'px' }">
          <main-content />
        </div>
      </div>
    </template>
  </div>
</template>

<script>
import MainNavbar from "./main-navbar";
import MainContent from "./main-content";
export default {
  provide() {
    return {
      // 刷新
      refresh() {
        this.$store.commit("common/updateContentIsNeedRefresh", true);
        this.$nextTick(() => {
          this.$store.commit("common/updateContentIsNeedRefresh", false);
        });
      },
    };
  },
  data() {
    return {
      loading: true,
    };
  },
  components: {
    MainNavbar,
    MainContent,
  },
  computed: {
    documentClientHeight: {
      get() {
        return this.$store.state.common.documentClientHeight;
      },
      set(val) {
        this.$store.commit("common/updateDocumentClientHeight", val);
      },
    },
    userId: {
      get() {
        return this.$store.state.user.id;
      },
      set(val) {
        this.$store.commit("user/updateId", val);
      },
    },
    userName: {
      get() {
        return this.$store.state.user.name;
      },
      set(val) {
        this.$store.commit("user/updateName", val);
      },
    },
  },
  created() {
    this.getUserInfo();
  },
  mounted() {
    this.resetDocumentClientHeight();
  },
  methods: {
    // 重置窗口可视高度
    resetDocumentClientHeight() {
      this.documentClientHeight = document.documentElement["clientHeight"];
      window.onresize = () => {
        this.documentClientHeight = document.documentElement["clientHeight"];
      };
    },
    // 获取当前管理员信息
    getUserInfo() {
      var uid = this.$cookie.get("userId");
      var userType = this.$cookie.get("userType");
      var URLPATH = "";
      if (userType == "student") {
        URLPATH = "/edu-student/student/info";
      }
      if (userType == "teacher") {
        URLPATH = "/edu-teacher/teacher/info";
      }
      this.$http({
        url: this.$http.adornUrl(`${URLPATH}`), //http://localhost:8082/eduservice/edu-teacher/teacher/20205532
        method: "get",
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        if (data && data.code === 20000) {
          this.loading = false;
          // userId.set(data.data.data.id);
          this.$store.commit("user/updateId", data.data.data.username);
          this.$store.commit("user/updateName", data.data.data.name);
          this.$store.commit("user/updateAvatar", data.data.data.avatar);
          this.$store.commit(
            "user/updateUserType",
            this.$cookie.get("userType")
          );
        }
      });
    },
  },
};
</script>
<style >
.navb {
  width: 81%;
  margin: 0 auto;
}
</style>
